<?php
include 'includes/db.php';
session_start();

if (!isset($_SESSION['user_id'])) {
    echo json_encode(['code' => 1, 'msg' => '用户未登录']);
    exit;
}

$token = 'pxpgg0hpgab0'; // 替换为你的实际 token
$movieName = $_GET['wd'] ?? '';

if (empty($movieName)) {
    echo json_encode(['code' => 3, 'msg' => '参数不完整']);
    exit;
}

$host = "https://xzdx.top/api/so";
$method = "GET";
$url = $host . "?token=" . urlencode($token) . "&wd=" . urlencode($movieName);

$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

$response = curl_exec($curl);
if (curl_errno($curl)) {
    echo json_encode(['code' => 2, 'msg' => '请求超时']);
    curl_close($curl);
    exit;
}

curl_close($curl);

$result = json_decode($response, true);

if ($result['code'] === 0) {
    echo json_encode(['code' => 0, 'data' => $result['data']]);
} else {
    echo json_encode(['code' => 1, 'msg' => $result['msg']]);
}